#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2019/9/29 5:59 下午
# @Author  : Hardy
# @File    : 03_basic.py
import tensorflow as tf


@tf.function
def add(a, b):
    return a + b

print(add(tf.ones([2, 2]), tf.ones([2, 2])))

v = tf.Variable(2.0)

with tf.GradientTape() as tape:
    res = add(v, 1.0)

print(tape.gradient(res, v))